package com.work.api.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.work.dto.bd.BdOperationProcessSearchDTO;
import com.work.dto.main.*;
import com.work.dto.transport.TransportSearchDTO;
import com.work.dto.transport.WorkArrangeSearchDTO;
import com.work.entity.main.GoodsPosition;
import com.work.service.bd.IBdOperationProcessService;
import com.work.service.bd.IBdTeamService;
import com.work.service.main.*;
import com.work.service.transport.ITransportService;
import com.work.vo.bd.BdOperationProcessVO;
import com.work.vo.bd.BdTeamTreeVO;
import com.work.vo.main.*;
import com.work.vo.transport.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * app控制器
 *
 * @author ：dujianyu
 * @since ：Created in 2024/2/23 9:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("app")
@Api(value = "app控制器 ", tags = "app控制器")
public class AppController extends BladeController {

    private IBdOperationProcessService bdOperationProcessService;
    private IBdTeamService bdTeamService;
    private ITransportService transportService;
    private IOneStockTallyService oneStockTallyService;
    private ITwoStockTallyService twoStockTallyService;
    private IShipBillStorageService storageService;
    private ITShipBillRemarkService shipBillRemarkService;
    private IBulkTallyService bulkTallyService;
    private ITallyMachineService tallyMachineService;
    private IRetreatSetService retreatSetService;
    private IGoodsPositionService goodsPositionService;

    @GetMapping("transport/shipList")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "货运船 ", notes = "传入dto")
    public R<List<TransportShipVO>> transportShipList(TransportSearchDTO dto) {
        List<TransportShipVO> list = transportService.selectTransportShipList(dto);
        return R.data(list);
    }

    @GetMapping("transport/shipDetail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "货运船详情", notes = "传入dto")
    public R<TransportShipVO> transportShipDetail(TransportSearchDTO dto) {
        return R.data(transportService.selectTransportShipDetail(dto));
    }

    @GetMapping("transport/billList")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "货运舱单", notes = "传入dto")
    public R<List<TransportBillVO>> transportBillList(TransportSearchDTO dto) {
        List<TransportBillVO> list = transportService.selectTransportBillList(dto);
        return R.data(list);
    }

    @GetMapping("transport/billDetail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "货运舱单详情", notes = "传入dto")
    public R<TransportBillVO> transportBillDetail(TransportSearchDTO dto) {
        return R.data(transportService.selectTransportBillDetail(dto));
    }

    @GetMapping("transport/packageTypeList")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "货运包装", notes = "传入dto")
    public R<List<TransportPackageTypeVO>> transportPackageTypeList(TransportSearchDTO dto) {
        List<TransportPackageTypeVO> list = transportService.selectTransportPackageTypeList(dto);
        return R.data(list);
    }

    @GetMapping("transport/shipCargoTypeList")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "获取该船舱单的货名", notes = "传入dto")
    public R<List<CargoTypeVO>> shipCargoTypeList(TransportSearchDTO dto) {
        return R.data(transportService.getShipCargoType(dto));
    }

    @GetMapping("transport/shipArrangeList")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "航运配工", notes = "传入dto")
    public R<List<WorkArrangeShipVO>> getShipArrange(WorkArrangeSearchDTO dto) {
        return R.data(transportService.selectWorkArrangeShipList(dto));
    }

    @GetMapping("transport/landArrangeList")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "陆运配工", notes = "传入dto")
    public R<List<WorkArrangeLandVO>> getLandArrange(WorkArrangeSearchDTO dto) {
        return R.data(transportService.selectWorkArrangeLandList(dto));
    }

    @GetMapping("transport/assignWorker")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "配工工人", notes = "传入dto")
    public R<List<AssignWorkerVO>> getAssignWorker(WorkArrangeSearchDTO dto) {
        return R.data(transportService.selectAssignWorkerList(dto));
    }

    @GetMapping("transport/assignMachineTree")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "配工机械树形", notes = "传入dto")
    public R<List<AssignMachineKindVO>> getAssignMachine(WorkArrangeSearchDTO dto) {
        return R.data(transportService.selectAssignMachineList(dto));
    }

    @GetMapping("bd/operationProcess/list")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "作业过程列表", notes = "传入dto")
    public R<List<BdOperationProcessVO>> operationProcessList(BdOperationProcessSearchDTO dto) {
        List<BdOperationProcessVO> list = bdOperationProcessService.selectBdOperationProcessList(dto);
        return R.data(list);
    }

    @GetMapping("bd/team/tree")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "队组树形", notes = "")
    public R<List<BdTeamTreeVO>> teamTree() {
        return R.data(bdTeamService.selectBdTeamTree());
    }

    @PostMapping("ost/appSubmit")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "app提交（理货员理货）", notes = "传入dto")
    public R<Boolean> ostAppSubmit(@Valid @RequestBody OneStockTallyAppSubmitDTO dto) {
        return R.status(oneStockTallyService.submitOneStockTally(dto));
    }


    @PostMapping("ost/appSubmitBatch")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "app提交（理货员理货）", notes = "传入dto")
    public R<Boolean> appSubmitBatch(@Valid @RequestBody OneStockTallyAppSubmitBatchDTO dto) {
        return R.status(oneStockTallyService.submitOneStockTallyBatch(dto));
    }

    @PostMapping("ost/remove")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "删除", notes = "传入id")
    public R<Boolean> ostRemove(@ApiParam(value = "主键", required = true) @RequestParam String id) {
        return R.status(oneStockTallyService.removeOneStockTally(Func.toLong(id)));
    }


    @GetMapping("ost/tallyHistory")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "单垛理货历史分页", notes = "传入dto")
    public R<IPage<OneStockTallyVO>> selectOsTallyHistoryP(OneStockTallySearchDTO dto, Query query) {
        IPage<OneStockTallyVO> pages = oneStockTallyService.selectOsTallyHistoryPage(Condition.getPage(query), dto);
        return R.data(pages);
    }

    @PostMapping("tst/appSubmit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "app提交（理货员理货）", notes = "传入dto")
    public R<Boolean> tstAppSubmit(@Valid @RequestBody TwoStockTallyAppSubmitDTO dto) {
        return R.status(twoStockTallyService.submitTwoStockTally(dto));
    }

    @PostMapping("tst/remove")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "删除多垛理货", notes = "传入id")
    public R<Boolean> tstRemove(@ApiParam(value = "主键", required = true) @RequestParam String id) {
        return R.status(twoStockTallyService.removeTwoStockTally(Func.toLong(id)));
    }

    @GetMapping("tst/tallyHistory")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "分页", notes = "传入dto")
    public R<IPage<TwoStockTallyVO>> selectTsTallyHistoryPage(TwoStockTallySearchDTO dto, Query query) {
        IPage<TwoStockTallyVO> pages = twoStockTallyService.selectTsTallyHistoryPage(Condition.getPage(query), dto);
        return R.data(pages);
    }

    @GetMapping("storage/getStorageByTransportBillId")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据货运舱单ID获取库存 ", notes = "传入DTO")
    public R<PieceTonVO> getStorageByTransportBillId(ShipBillStorageSearchDTO dto) {
        return R.data(storageService.getStorageByTransportBillId(dto));
    }


    @GetMapping("storage/getStorageDetail")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "场存详情 ", notes = "传入DTO")
    public R<ShipBillStorageVO> getStorageDetail(ShipBillStorageSearchDTO dto) {
        return R.data(storageService.getStorageDetail(dto));
    }

    @GetMapping("storage/shipBillStorageList")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "场存列表", notes = "传入DTO")
    public R<List<ShipBillStorageVO>> selectShipBillStorageList(ShipBillStorageSearchDTO dto) {
        return R.data(storageService.selectShipBillStorageList(dto));
    }

    @GetMapping("tShipBillRemark/list")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "理货交班记录列表 ", notes = "传入DTO")
    public R<List<TShipBillRemarkVO>> list(TShipBillRemarkSearchDTO dto) {
        return R.data(shipBillRemarkService.selectShipBillRemarkList(dto));
    }

    @PostMapping("bt/appSubmit")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "散货外捣app提交", notes = "传入dto")
    public R<Boolean> appSubmit(@Valid @RequestBody BulkTallyAppSubmitDTO dto) {
        return R.status(bulkTallyService.submitBulkTally(dto));
    }

    @PostMapping("bt/remove")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "删除散货外捣", notes = "传入id")
    public R<Boolean> btRemove(@ApiParam(value = "主键", required = true) @RequestParam String id) {
        return R.status(bulkTallyService.removeBulkTally(Func.toLong(id)));
    }

    @GetMapping("bt/tallyHistory")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "散货外捣分页", notes = "传入dto")
    public R<IPage<BulkTallyVO>> selectBulkTallyHistoryPage(BulkTallySearchDTO dto, Query query) {
        IPage<BulkTallyVO> pages = bulkTallyService.selectBulkTallyHistoryPage(Condition.getPage(query), dto);
        return R.data(pages);
    }

    @GetMapping("tally/machineTree")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "理货机械树形", notes = "传入dto")
    public R<List<TallyMachineKindVO>> selectTallyMachineTree(TallyMachineSearchDTO dto) {
        List<TallyMachineKindVO> data = tallyMachineService.selectTallyMachineTree(dto);
        return R.data(data);
    }

    @PostMapping("retreat/submit")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "退关设置提交", notes = "传入dto")
    public R<Boolean> retreatSubmit(@Valid @RequestBody RetreatSetAppSubmitDTO dto) {
        return R.status(retreatSetService.submitRetreatSet(dto));
    }


    @PostMapping("retreat/remove")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "删除", notes = "传入id")
    public R<Boolean> remove(@ApiParam(value = "主键", required = true) @RequestParam String id) {
        return R.status(retreatSetService.removeRetreatSet(Func.toLong(id)));
    }

    @GetMapping("retreat/retreatSetPage")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "分页", notes = "传入dto")
    public R<IPage<RetreatSetVO>> selectRetreatSetPage(RetreatSetSearchDTO dto, Query query) {
        IPage<RetreatSetVO> pages = retreatSetService.selectRetreatSetPage(Condition.getPage(query), dto);
        return R.data(pages);
    }


    @GetMapping("retreat/retreatTallyList")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "提货操作列表", notes = "传入dto")
    public R<List<RetreatTallyVO>> selectRetreatTallyList(RetreatSetSearchDTO dto) {
        List<RetreatTallyVO> data = retreatSetService.selectRetreatTallyList(dto);
        return R.data(data);
    }

    @GetMapping("retreat/retreatTotal")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "退关总计", notes = "传入dto")
    public R<RetreatTotalVO> selectRetreatTotal(RetreatSetSearchDTO dto) {
        RetreatTotalVO data = retreatSetService.selectRetreatTotal(dto);
        return R.data(data);
    }

    @PostMapping("goodsPosition/save")
    @ApiOperationSupport(order = 11)
    @ApiOperation(value = "货垛地图信息保存", notes = "传入entity")
    public R<String> saveGoodsPosition(@RequestBody GoodsPosition entity) {
        goodsPositionService.save(entity);
        return R.data(entity.getId().toString());
    }

    @GetMapping("goodsPosition/getJsonData")
    @ApiOperationSupport(order = 11)
    @ApiOperation(value = "获取货垛地图信息", notes = "传入主键ID")
    public R<String> getGoodsPosition(String id) {
        GoodsPosition byId = goodsPositionService.getById(Func.toLong(id));
        if (byId != null) {
            return R.data(byId.getJsonData());
        }

        return R.data("");
    }

}
